<?php


// 《模拟人生历程生成器_demo》


// 出生背景
class Brith{    
    private $brithNumber = 0;

    public function __construct($age){
        // 年龄
        $brithNumber = $age;
        $dateTime = new DateTime();
        $now_time = $dateTime->format('Y-m-d H:i:s');
        // echo "<h3 style='color:red'>" . $now_time . "</h3>";
        echo "<h3 style='color:red'>{$now_time}</h3>"; // 用这种比上面的写法好一点的哦

        echo "那年，你 {$brithNumber} 岁";
        
        // 出生背景
        $this->brithNumber = rand(1, 3);
        switch($this->brithNumber)
        {
            case 1:
                $this->poor();
                break;
            case 2:
                $this->middle();
                break;
            case 3:
                $this->rich();
                break;
            default:
                break;
        }
    }

    private function poor(){
        echo "<h3>你出生于一个贫困家庭。</h3>" . "<br>";
    }

    private function middle(){
        echo "<h3>你出生于一个中产家庭。</h3>" . "<br>";
    }

    private function rich(){
        echo "<h3>你出生于一个富有家庭。</h3>" . "<br>";
    }
};

// 职业
class Occupation{
    private $brithNumber = 0;

    public function __construct($age){
        // 年龄
        $time = null; // 不写的话会有问题的哦
        $brithNumber = $age;
        $number = rand(18, 24);
        $brithNumber += $number;
        $interval = "+{$number} year";
        $now_time = date('Y-m-d H:i:s', strtotime($time . ' ' . $interval));

        // $dateTime = new DateTime();
        // $now_time = $dateTime->format('Y-m-d H:i:s');
        // echo "<h3 style='color:red'>" . $now_time . "</h3>";
        // echo "<h3 style='color:red'>{$now_time}</h3>"; // 用这种比上面的写法好一点的哦
        echo "那年，你 {$brithNumber} 岁";
        
        $this->brithNumber = rand(1, 4);
        switch($this->brithNumber)
        {
            case 1:
                $this->doctor();
                break;
            case 2:
                $this->lawyer();
                break;
            case 3:
                $this->teacher();
                break;
            case 4:
                $this->programmer();
                break;
            default:
                break;
        }
    }

    private function doctor(){
        echo "<h3>你成为了一名医生。</h3>" . "<br>";
    }

    private function lawyer(){
        echo "<h3>你成为了一名律师。</h3>" . "<br>";
    }

    private function teacher(){
        echo "<h3>你成为了一名老师。</h3>" . "<br>";
    } 

    private function programmer(){
        echo "<h3>你成为了一名程序员。</h3>" . "<br>";
    } 
};

// 生活事件
class LiveEvent{
    private $brithNumber = 0;

    public function __construct($age){
        // 年龄
        $time = null; // 不写的话会有问题的哦
        $brithNumber = $age;
        $number = rand(27, 32);
        $brithNumber += $number;
        $interval = "+{$number} year";
        $now_time = date('Y-m-d H:i:s', strtotime($time . ' ' . $interval));

        echo "那年，你 {$brithNumber} 岁";
        
        $this->brithNumber = rand(1, 4);
        switch($this->brithNumber)
        {
            case 1:
                $this->award();
                break;
            case 2:
                $this->up();
                break;
            case 3:
                $this->down();
                break;
            case 4:
                $this->programmer_down();
                break;
            default:
                break;
        }
    }

    private function award(){
        echo "<h3>你中彩票了。</h3>" . "<br>";
    }

    private function up(){
        echo "<h3>你升官了。</h3>" . "<br>";
    }

    private function down(){
        echo "<h3>你被贬了。</h3>" . "<br>";
    } 

    private function programmer_down(){
        echo "<h3>失业了</h3>" . "<br>";
    } 
};

// 结束
class End{
    private $brithNumber = 0;

    public function __construct($age){
        // 年龄
        $time = null; // 不写的话会有问题的哦
        $brithNumber = $age;
        $number = rand(68, 100);
        $brithNumber += $number;
        $interval = "+{$number} year";
        $now_time = date('Y-m-d H:i:s', strtotime($time . ' ' . $interval));

        echo "那年，你 {$brithNumber} 岁";
        
        $this->brithNumber = rand(1, 4);
        switch($this->brithNumber)
        {
            case 1:
                $this->cheng_gong();
                break;
            case 2:
                $this->shi_bai();
                break;
            case 3:
                $this->bei_ji_nian();
                break;
            case 4:
                $this->programmer_up();
                break;
            default:
                break;
        }
    }

    private function cheng_gong(){
        echo "<h3>你成功了，实现了你自己的梦想。</h3>" . "<br>";
    }

    private function shi_bai(){
        echo "<h3>你失败了，没实现你的梦想。</h3>" . "<br>";
    }

    private function bei_ji_nian(){
        echo "<h3>你成功了，被后代纪念。</h3>" . "<br>";
    } 

    private function programmer_up(){
        echo "<h3>你成为了你自己。</h3>" . "<br>";
    } 
};

function main(){
    $age = 0;
    new Brith($age);
    new Occupation($age);
    new LiveEvent($age);
    new End($age);

    return 0;
}


main(); // 调用主函数，运行程序

